<template>
	<view class="">
		<!-- 状态栏 -->
		<view class="status_bar">
		</view>
		<view class="home-index">
			<Tabs></Tabs>
			<view class="content">
				<view class="header">
					<view class="title">
						首页
					</view>
					<image src="../../static/images/sousuo.png" mode="" @click="toSearch"></image>
				</view>
				<view class="wrap">
					<view class="cLeft">
						<view class="tabs">
							<view class="tab">
								<view class="name">
									设备总数
								</view>
								<view class="num">
									{{deviceCount}}
								</view>
							</view>
							<view class="tab">
								<view class="name">
									企业总数
								</view>
								<view class="num">
									{{companyCount}}
								</view>
							</view>
						</view>
						<view class="listWrap">
							<view class="title">
								<view class="name">
									最新企业
								</view>
								<image style="width: 16px;height: 18px;" src="../../static/images/arrow.png" mode=""></image>
							</view>
							<scroll-view scroll-y="true" class="scroll-index">
								<view class="list">
									<view class="item" v-for="(item,index) in deviceCountList" :key='index'>
										<view class="itemName">
											{{item.companyName}}
										</view>
										<view class="num">
											<view class="dot">
												<image src="../../static/images/video.png" mode=""></image>
											</view>
											{{item.deviceCount}}
										</view>
									</view>
								</view>
							</scroll-view>
							
						</view>
					</view>
					<view class="cRight">
						<view class="nav">
							<view :class="['navItem',activeIndex==0?'active':'']" @click="changeTab(0)">
								周
							</view>
							<view :class="['navItem',activeIndex==1?'active':'']" @click="changeTab(1)">
								月
							</view>
							<view :class="['navItem',activeIndex==2?'active':'']" @click="changeTab(2)">
								半年
							</view>
							<view :class="['navItem',activeIndex==3?'active':'']" @click="changeTab(3)">
								年
							</view>
						</view>
						 <qiun-data-charts type="line" :chartData="chartData" />
					</view>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	import http from '../../api/http.js'
	import Tabs from '../../components/tabs.vue'
	console.log(http,"http对象")
	export default {
		data() {
			return {
				activeIndex:0,
				deviceCount:0,
				companyCount:0,
				deviceCountList:[],
				chartData:{
				  categories: ["2016", "2017", "2018", "2019", "2020", "2021"],
				  series: [{
				    name: "设备数量",
				    data: [35, 36, 31, 33, 13, 34]
				  }]
				}
			}
		},
		components:{
			Tabs
		},
		onLoad() {
			this.getDeviceCount()
			this.getCompanyCount()
			this.getCompanyDeviceCountList()
		},
		methods: {
			changeTab(index){
				this.activeIndex = index;
			},
			toSearch(){
				uni.navigateTo({
					url:'/pages/search/search'
				})
			},
			//获取设备输
			getDeviceCount(){
				http.post('app/getDeviceCount').then(res=>{
					console.log(res,"设备数")
					this.deviceCount = res.deviceCount
				})
			},
			//企业总数
			getCompanyCount(){
				http.post('app/getCompanyCount').then(res=>{
					console.log(res,"设备数")
					this.companyCount = res.deviceCount
				})
			},
			//获取最新企业及管理设备数量
			getCompanyDeviceCountList(){
				http.post('app/getCompanyDeviceCountList').then(res=>{
					console.log(res,"设备列表")
					this.deviceCountList = res.deviceCountList
				})
			}
		}
	}
</script>
<style>
	.status_bar {
		height: var(--status-bar-height);
		width: 100%;
		background-color: #FFFFFF;
	}
</style>
<style lang="less" scoped>
.home-index{
	display: flex;
	height: calc(100vh - var(--status-bar-height));
	.content{
		display: flex;
		flex-direction: column;
		flex:1;
		background-color: #D4E7F1;
		.header{
			display: flex;
			justify-content: space-between;
			align-items: center;
			// border-bottom: 1px solid #F3F3F3;
			height: 60px;
			// background-color: red;
			padding: 0 10px;
			
			.title{
				display: flex;
				align-items: center;
				font-size: 24px;
				color: #235FA7;
			}
			image{
				width: 20px;
				height: 20px;
			}
		}
	
	
		.wrap{
			display: flex;
			flex:1;
			
			// background-color: red;
			.cLeft{
				display: flex;
				flex-direction: column;
				flex:1;
				// width: 50%;
				padding: 0 10px;
				.tabs{
					display: flex;
					.tab{
						display: flex;
						flex-direction: column;
						justify-content: center;
						align-items: center;
						padding: 0 10px;
						height: 60px;
						background-color: white;
						border-radius: 10px;
						margin-right: 20px;
						.name{
							font-size: 14px;
							color: #666;
						}
						.num{
							font-size: 18px;
							color: #4A85BE;
							font-weight: bold;
						}
					}
				}
				.scroll-index{
					height: calc(100vh - 180px - var(--status-bar-height));
				}
				.listWrap{
					display: flex;
					flex-direction: column;
					.title{
						display: flex;
						align-items: center;
						justify-content: space-between;
						height: 60px;
						.name{
							font-size: 22px;
							color: #4A85BE;
						}
					}
					.list{
						display: flex;
						flex-direction: column;
						background-color: #E3F2F6;
						box-shadow: 10px 10px 10px 10px rgba(193,217,234, 0.5);
						padding: 0 10px;
						border-radius: 10px;
						.item{
							display: flex;
							justify-content: space-between;
							align-items: center;
							height: 60px;
							
							.itemName{
								font-size: 18px;
								color: #4A85BE;
							}
							.num{
								display: flex;
								align-items: center;
								font-size: 14px;
								color: #4A85BE;
								.dot{
									display: flex;
									justify-content: center;
									align-items: center;
									width:40px ;
									height: 40px;
									background-color: #4A85BE;
									border-radius: 50%;
									margin-right: 10px;
									image{
										width: 24px;
										height: 24px;
									}
								}
							}
						}
					}
				}
			}
			.cRight{
				display: flex;
				flex-direction: column;
				// justify-content: center;
				// align-items: center;
				flex:1;
				.nav{
					display: flex;
					background-color: red;
					margin: 0 25px;
					background-color: #DCECF4;
					.navItem{
						display: flex;
						justify-content: center;
						align-items: center;
						height: 30px;
						flex:1;
						color: #999999;
					}
					.active{
						color: #4A85BE;
						border:1px solid #4A85BE
					}
				}
				// width: 50%;
				// background-color: white;
			}
		}
	}
	
	
}
</style>
